import {  useRoutes,Navigate,createBrowserRouter } from "react-router-dom";

// import Home from "@/pages/Home/Home";
import Lazyout from "../layout/index.jsx";
// import Login from "@/pages/Login/Login";
import LazyLoad from "@/hooks/LazyLoad";
import React from "react"; 

function Ad({children}){
    const token=localStorage.getItem('token')
    return token?children:<Navigate to='/login' />
}
export const routerlist=[
    {
        path:'/home',
        element:<Ad>{LazyLoad(React.lazy(()=>import("@/pages/Home/Home")))}</Ad>,
        meta:{title:'首页'}
    },
    {
        path:'/detail',
        // element:LazyLoad(React.lazy(()=>import("@/pages/Detail/Detail"))),
        meta:{title:'详情'},
        children:[
            {
                path:'/detail/one',
                element:LazyLoad(React.lazy(()=>import("@/pages/One/One"))),
                meta:{title:'详情壹'}
            },
            {
                path:'/detail/two',
                element:LazyLoad(React.lazy(()=>import("@/pages/Two/Two"))),
                meta:{title:'详情贰'}
            },
        ]
    }
]
export const router=createBrowserRouter([
    {
        path:'/',
        // element:<Navigate to='/login' />,
        element:<Lazyout />,
        children:routerlist
    },
    {
        path:'/login',
        element:LazyLoad(React.lazy(()=>import('@/pages/Login/Login'))),
        // meta:{title:'登录'}
    },
    
])

// const Router=()=>{
//     const routes=useRoutes(router)
//     return routes
// }

// export default Router